home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / spxcht.arc / RECSPX.C < prev    next >
C/C++ Source or Header  |  1988-01-04  |  4KB  |  120 lines

  1. #include <stdio.h>
  2. #include <nit.h>
  3. #include "bill.h"
  4.  
  5. unsigned int   Socket=0x5555;
  6.  
  7. long stats=0;
  8.  
  9. char   *ReadData;
  10.  
  11. main(argc,argv)
  12. int argc;
  13. char *argv[];
  14. {
  15.     int            ccode, ConnectionID, i=0;
  16.     ECBStructure    *PoolECB, *ConnectionECB;
  17.     SPXStructure    *PoolSPX, *ConnectionSPX;
  18.     char        far  *farcharpointer;
  19.     char             *data;
  20.     void ReceiveESRHandler();
  21.  
  22.     ReadData = (char *)myalloc(1, 2);
  23.  
  24.  
  25.     IPXInitialize();
  26.     /* ********************************************************** */
  27.     if ((ccode = IPXOpenSocket(&Socket,0x00)) != 0) {
  28.         printf("A socket was not opened");
  29.         exit(-1);
  30.     }
  31.     /* ********************************************************** */
  32.     while (i++ != 5) {
  33.         if ((PoolECB = (ECBStructure *)myalloc(1, sizeof(ECBStructure))) == NULL ) {
  34.             printf("Out of memory trying to allocate for the PoolECB\n ");
  35.             exit(-1);
  36.         }
  37.         if ((PoolSPX = (SPXStructure *)myalloc(1, sizeof(SPXStructure))) == NULL ) {
  38.             printf("Out of memory trying to allocate for the PoolSPX\n ");
  39.         }
  40.         data = (char *)myalloc(1, 2);
  41.  
  42.         farcharpointer = (char far *)ReceiveESRHandler;
  43.         PoolECB->ESRAddress = farcharpointer;
  44.         PoolECB->ECBSocket = Socket;
  45.         PoolECB->FragmentCount = 2;
  46.         farcharpointer = (char far *)PoolSPX;
  47.         PoolECB->FragmentDescriptor[0].Address = farcharpointer;
  48.         PoolECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
  49.         farcharpointer = (char far *)data;
  50.         PoolECB->FragmentDescriptor[1].Address = farcharpointer;
  51.         PoolECB->FragmentDescriptor[1].Size = 2;
  52.         PoolSPX->PacketType = (char)5;
  53.         PoolSPX->PacketLength = IntSwap( sizeof(SPXStructure));
  54.  
  55.         SPXListenForSequencedPacket(PoolECB);
  56.     }
  57.     /* ************************************************************** */
  58.         if ((ConnectionECB = (ECBStructure *)myalloc(1, sizeof(ECBStructure))) == NULL) {
  59.                 printf("Out of memory allocating for ConnectionECB\n ");
  60.  
  61.                 
  62.                 
  63.                 exit(-1);
  64.             }
  65.         if ((ConnectionSPX = (SPXStructure *)myalloc(1,sizeof(SPXStructure))) == NULL) {
  66.             printf("Out of memory allocating for ConnectionSPX\n");
  67.             exit(-1);
  68.             }
  69.  
  70.         ConnectionSPX->PacketLength = IntSwap(sizeof(SPXStructure));
  71.         ConnectionSPX->PacketType = (char)5;
  72.         ConnectionECB->ECBSocket = Socket;
  73.         ConnectionECB->FragmentCount = 1;
  74.         farcharpointer = (char far *)ConnectionSPX;
  75.         ConnectionECB->FragmentDescriptor[0].Address = farcharpointer;
  76.         ConnectionECB->FragmentDescriptor[0].Size = sizeof(SPXStructure);
  77.  
  78.         printf("\n\nWe are now in the mode of waiting for a connection....\n");
  79.         SPXListenForConnection((char)0, (char)0, ConnectionECB);
  80.         while (ConnectionECB->InUse) {
  81.             IPXRelinquishControl();
  82.             if (kbhit())
  83.                 exit(0);
  84.         }
  85.         switch (ConnectionECB->CompletionCode) {
  86.         case 0x00:
  87.             memcpy((char *)&ConnectionID, (char *)ConnectionECB->IPXWorkspace, 2);
  88.             printf("Connection ID is:  %x\n",ConnectionID);
  89.             break;
  90.         default:
  91.             printf("Connection was not established");
  92.             exit(-1);
  93.             break;
  94.         }
  95.     /* ****************************************************************** */
  96.     *ReadData = 0xFF;
  97.     while (!kbhit()) {
  98.         if (strcmp(*ReadData,(char)0xFF) != 0) {
  99.             if (strcmp(*ReadData,(char)0x1B) == 0)
  100.                 exit(0);
  101.             printf("%c",*ReadData);
  102.             if (strcmp(*ReadData,(char)0x0D) == 0)
  103.                 printf("\n");
  104.             *ReadData = 0xFF;
  105.         }
  106.     }
  107.  
  108. }
  109.  
  110. void ReceiveESR(ESR_ECB)
  111. ECBStructure    *ESR_ECB;
  112. {
  113.     char far *farcharpointer;
  114.  
  115.     farcharpointer = ESR_ECB->FragmentDescriptor[1].Address;
  116.     ReadData = (char *)farcharpointer;
  117.     stats++;
  118.     SPXListenForSequencedPacket(ESR_ECB);
  119. }
  120.